package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.WkspTaskCard;
import com.ruoyi.mes.service.IWkspTaskCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.mes.domain.ProCraftProcess;

/**
 * 车间任务卡Controller
 * 
 * @author CFL
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/mes/card")
public class WkspTaskCardController extends BaseController
{
    @Autowired
    private IWkspTaskCardService wkspTaskCardService;

    /**
     * 查询车间任务卡列表
     */
    @PreAuthorize("@ss.hasPermi('mes:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(WkspTaskCard wkspTaskCard)
    {
        startPage();
        List<WkspTaskCard> list = wkspTaskCardService.selectWkspTaskCardList(wkspTaskCard);
        return getDataTable(list);
    }

    /**
     * 导出车间任务卡列表
     */
    @PreAuthorize("@ss.hasPermi('mes:card:export')")
    @Log(title = "车间任务卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WkspTaskCard wkspTaskCard)
    {
        List<WkspTaskCard> list = wkspTaskCardService.selectWkspTaskCardList(wkspTaskCard);
        ExcelUtil<WkspTaskCard> util = new ExcelUtil<WkspTaskCard>(WkspTaskCard.class);
        util.exportExcel(response, list, "车间任务卡数据");
    }

    /**
     * 获取车间任务卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:card:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wkspTaskCardService.selectWkspTaskCardById(id));
    }

    /**
     * 报工查询接口
     */
    @PreAuthorize("@ss.hasPermi('mes:card:report:query')")
    @GetMapping(value = "/report/{proId}")
    public TableDataInfo getReportWork(@PathVariable("proId") Long proId)
    {
        List<ProCraftProcess> list = wkspTaskCardService.selectProcess(proId);
        return getDataTable(list);
    }

    /**
     * 新增车间任务卡
     */
    @PreAuthorize("@ss.hasPermi('mes:card:add')")
    @Log(title = "车间任务卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WkspTaskCard wkspTaskCard)
    {
        return toAjax(wkspTaskCardService.insertWkspTaskCard(wkspTaskCard));
    }


    /**
     * 修改车间任务卡
     */
    @PreAuthorize("@ss.hasPermi('mes:card:edit')")
    @Log(title = "车间任务卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WkspTaskCard wkspTaskCard)
    {
        return toAjax(wkspTaskCardService.updateWkspTaskCard(wkspTaskCard));
    }

    /**
     * 删除车间任务卡
     */
    @PreAuthorize("@ss.hasPermi('mes:card:remove')")
    @Log(title = "车间任务卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wkspTaskCardService.deleteWkspTaskCardByIds(ids));
    }
}
